﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;

namespace StockMarketTool.Converter
{
    public class StockValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double v = 0.0d;
            double opacity = 1.0d;
            if (double.TryParse(value.ToString(), out v))
            {
                if (parameter != null)
                {
                    if (!double.TryParse(parameter.ToString(), out opacity))
                        opacity = 1;
                }
                if (v >= 0.0d)
                {
                    return new SolidColorBrush() { Color = Colors.Red, Opacity = opacity };
                }
            }
            return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#008800"));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
